package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    public void add(ClueTrackRecordVo clueTrackRecordVo) {
        //1.更新线索
        TbClue tbClue = new TbClue();
        tbClue.setId(clueTrackRecordVo.getClueId());
        tbClue.setSubject(clueTrackRecordVo.getSubject());
        tbClue.setLevel(clueTrackRecordVo.getLevel());
        tbClue.setName(clueTrackRecordVo.getName());
        tbClue.setSex(clueTrackRecordVo.getSex());
        tbClue.setWeixin(clueTrackRecordVo.getWeixin());
        tbClue.setQq(clueTrackRecordVo.getQq());
        tbClue.setAge(clueTrackRecordVo.getAge());
        tbClue.setUpdateBy(SecurityUtils.getUsername());
        tbClue.setUpdateTime(DateUtils.getNowDate());
        tbClueMapper.updateTbClue(tbClue);
        //2.插入线索
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        tbClueTrackRecord.setClueId(clueTrackRecordVo.getClueId());
        tbClueTrackRecord.setRecord(clueTrackRecordVo.getRecord());
        tbClueTrackRecord.setType(clueTrackRecordVo.getType());
        tbClueTrackRecord.setFalseReason(clueTrackRecordVo.getFalseReason());
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        tbClueTrackRecord.setLevel(clueTrackRecordVo.getLevel());
        tbClueTrackRecord.setNextTime(clueTrackRecordVo.getNextTime());
        tbClueTrackRecord.setSubject(clueTrackRecordVo.getSubject());
        tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);
    }

    @Override
    public List<TbClueTrackRecord> getClueTrackRecordListByClueId(Long clueId) {
        return tbClueTrackRecordMapper.getClueTrackRecordListByClueId(clueId);
    }
}
